<template>
  <div>
    <h3 style="margin-left:20px">添加</h3>
  </div>
  <el-form ref="ruleFormRef" :model="state.addform" :rules="rules" label-width="120px" class="demo-ruleForm"
    status-icon>
    <el-form-item label="地址" prop="name">
      <el-input v-model="state.addform.name" clearable style="width: 250px;" type="text" />
    </el-form-item>

  </el-form>
  <div class="subm">
    <el-button size="small" @click="info">取消</el-button>
    <el-button type="primary" size="small" @click="add">添加</el-button>
  </div>
</template>

<script lang="ts" setup>
import { reactive } from "@vue/reactivity";
import { ElMessage } from "element-plus";
import { addaddress } from "../../api/address";
import { useRouter } from "vue-router";
const router = useRouter();
const state = reactive({
  addform: {
    name: "",
  },
});
const rules = reactive({
  name: [{ required: true, message: "请填写地址", trigger: "blur" }],
});
const add = async () => {
  let res: any = await addaddress(state.addform);
  if (res.code == 10000) {
    ElMessage({
      message: "添加成功",
      type: "success",
    });
    router.push("/address/addresslist");
  } else {
    return alert("数据错误");
  }
};
const info=()=>{
  router.push("/address/addresslist");
}
</script>

<style lang="less" scoped>
.subm {
  margin: 10px 0 0 150px;
}
</style>